import { LoginRes } from "@/types/login";
import { configureStore, createSlice, PayloadAction } from "@reduxjs/toolkit";
import { persistStore, REHYDRATE } from "redux-persist";
export interface ICommonState {
  loading: boolean;
  employee?: LoginRes;
}

const initialState: ICommonState = {
  loading: false,
  employee: undefined,
};
export const commonSlice = createSlice({
  name: "common",
  initialState,
  reducers: {
    setLoading(state, action) {
      state.loading = action.payload;
    },
    setEmployee(state, action: PayloadAction<LoginRes>) {
      console.log(action);

      state.employee = action.payload || undefined;
    },
  },
  extraReducers(builder) {
    builder.addCase(REHYDRATE, (state) => {
      console.log(state, "/....");
    });
  },
});

export const { setLoading, setEmployee } = commonSlice.actions;

export default configureStore({
  reducer: commonSlice.reducer,
});
